package cn.highedu.coolsharkhub.controller;

import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Session演示控制器
 * @author HighEDU
 */
@RestController
public class SessionDemoController {
    Logger logger = LoggerFactory.getLogger(SessionDemoController.class);

    /**
     * 设置Session
     */
    @GetMapping("/setsession")
    public String setSession(HttpSession session) {
        logger.info("设置Session");
        session.setAttribute("username", "HighEDU");
        return "设置Session";
    }

    /**
     * 获取Session
     */
    @GetMapping("/getsession")
    public String getSession(HttpSession session) {
        logger.info("获取Session");
        String username = (String) session.getAttribute("username");
        logger.info("Session: {}", username);
        return "获取Session";
    }

    /**
     * 清除Session
     */
    @GetMapping("/clearsession")
    public String clearSession(HttpSession session) {
        logger.info("清除Session");
        session.invalidate();
        return "清除Session";
    }
}
